package com.ruoyi.controller.production;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.production.MesProductionPickingDetail;
import com.ruoyi.service.production.IMesProductionPickingDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 生产领料单明细Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/production/pickingDetail")
public class MesProductionPickingDetailController extends BaseController {
    @Autowired
    private IMesProductionPickingDetailService IMesProductionPickingDetailService;

    /**
     * 查询生产领料单明细列表
     */
    @PreAuthorize("@ss.hasPermi('production:pickingDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesProductionPickingDetail mesProductionPickingDetail) {
        startPage();
        List<MesProductionPickingDetail> list = IMesProductionPickingDetailService.selectMesProductionPickingDetailList(mesProductionPickingDetail);
        return getDataTable(list);
    }

    /**
     * 导出生产领料单明细列表
     */
    @PreAuthorize("@ss.hasPermi('production:pickingDetail:export')")
    @Log(title = "生产领料单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesProductionPickingDetail mesProductionPickingDetail) {
        List<MesProductionPickingDetail> list = IMesProductionPickingDetailService.selectMesProductionPickingDetailList(mesProductionPickingDetail);
        ExcelUtil<MesProductionPickingDetail> util = new ExcelUtil<MesProductionPickingDetail>(MesProductionPickingDetail.class);
        util.exportExcel(response, list, "生产领料单明细数据");
    }

    /**
     * 获取生产领料单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:pickingDetail:query')")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId) {
        return success(IMesProductionPickingDetailService.selectMesProductionPickingDetailByDetailId(detailId));
    }

    /**
     * 新增生产领料单明细
     */
    @PreAuthorize("@ss.hasPermi('production:pickingDetail:add')")
    @Log(title = "生产领料单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesProductionPickingDetail mesProductionPickingDetail) {
        return toAjax(IMesProductionPickingDetailService.insertMesProductionPickingDetail(mesProductionPickingDetail));
    }

    /**
     * 修改生产领料单明细
     */
    @PreAuthorize("@ss.hasPermi('production:pickingDetail:edit')")
    @Log(title = "生产领料单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesProductionPickingDetail mesProductionPickingDetail) {
        return toAjax(IMesProductionPickingDetailService.updateMesProductionPickingDetail(mesProductionPickingDetail));
    }

    /**
     * 删除生产领料单明细
     */
    @PreAuthorize("@ss.hasPermi('production:pickingDetail:remove')")
    @Log(title = "生产领料单明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds) {
        return toAjax(IMesProductionPickingDetailService.deleteMesProductionPickingDetailByDetailIds(detailIds));
    }

    /**
     * 根据领料单ID查询明细列表
     */
    @PreAuthorize("@ss.hasPermi('production:pickingDetail:list')")
    @GetMapping("/listByPickingId/{pickingId}")
    public AjaxResult listByPickingId(@PathVariable Long pickingId) {
        List<MesProductionPickingDetail> list = IMesProductionPickingDetailService.selectDetailListByPickingId(pickingId);
        return success(list);
    }

    /**
     * 批量新增生产领料单明细
     */
    @PreAuthorize("@ss.hasPermi('production:pickingDetail:add')")
    @Log(title = "批量新增生产领料单明细", businessType = BusinessType.INSERT)
    @PostMapping("/batchAdd")
    public AjaxResult batchAdd(@RequestBody List<MesProductionPickingDetail> detailList) {
        return toAjax(IMesProductionPickingDetailService.batchInsertMesProductionPickingDetail(detailList));
    }

    /**
     * 根据领料单ID删除明细
     */
    @PreAuthorize("@ss.hasPermi('production:pickingDetail:remove')")
    @Log(title = "删除生产领料单明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteByPickingId/{pickingId}")
    public AjaxResult deleteByPickingId(@PathVariable Long pickingId) {
        return toAjax(IMesProductionPickingDetailService.deleteMesProductionPickingDetailByPickingId(pickingId));
    }
}